package net.lab1024.sa.admin.module.business.core.material.controller;

import net.lab1024.sa.admin.module.business.core.material.domain.form.MaterialCategoryAddForm;
import net.lab1024.sa.admin.module.business.core.material.domain.form.MaterialCategoryQueryForm;
import net.lab1024.sa.admin.module.business.core.material.domain.form.MaterialCategoryUpdateForm;
import net.lab1024.sa.admin.module.business.core.material.domain.vo.MaterialCategoryTreeVo;
import net.lab1024.sa.admin.module.business.core.material.domain.vo.MaterialCategoryVO;
import net.lab1024.sa.admin.module.business.core.material.service.MaterialCategoryService;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;

import java.util.List;

/**
 * 物料分类表 Controller
 *
 * @Author ADog
 * @Date 2025-09-19 19:48:13
 * @Copyright 1.0
 */

@RestController
@Tag(name = "物料分类表")
public class MaterialCategoryController {

    @Resource
    private MaterialCategoryService materialCategoryService;

    @Operation(summary = "分页查询 @author ADog")
    @PostMapping("/materialCategory/queryPage")
    @SaCheckPermission("materialCategory:query")
    public ResponseDTO<PageResult<MaterialCategoryVO>> queryPage(@RequestBody @Valid MaterialCategoryQueryForm queryForm) {
        return ResponseDTO.ok(materialCategoryService.queryPage(queryForm));
    }

    @Operation(summary = "获取分类树 @author ADog")
    @GetMapping("/materialCategory/getTree")
    @SaCheckPermission("materialCategory:query")
    public List<MaterialCategoryTreeVo> getTree() {
        return materialCategoryService.getTree();
    }

    @Operation(summary = "添加 @author ADog")
    @PostMapping("/materialCategory/add")
    @SaCheckPermission("materialCategory:add")
    public ResponseDTO<String> add(@RequestBody @Valid MaterialCategoryAddForm addForm) {
        return materialCategoryService.add(addForm);
    }

    @Operation(summary = "更新 @author ADog")
    @PostMapping("/materialCategory/update")
    @SaCheckPermission("materialCategory:update")
    public ResponseDTO<String> update(@RequestBody @Valid MaterialCategoryUpdateForm updateForm) {
        return materialCategoryService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author ADog")
    @PostMapping("/materialCategory/batchDelete")
    @SaCheckPermission("materialCategory:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return materialCategoryService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author ADog")
    @GetMapping("/materialCategory/delete/{materialCategoryId}")
    @SaCheckPermission("materialCategory:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Long materialCategoryId) {
        return materialCategoryService.delete(materialCategoryId);
    }
}
